#region Using

using System;
using System.Xml;
using System.IO;
using System.Globalization;
using System.Collections.Generic;
using System.Collections.Specialized;
using BlogEngine.Core;
using System.Linq;
using AzureProvider.SoupMethods;

#endregion

namespace BlogEngine.Core.Providers
{
  /// <summary>
  /// A storage provider for BlogEngine that uses XML files.
  /// <remarks>
  /// To build another provider, you can just copy and modify
  /// this one. Then add it to the web.config's BlogEngine section.
  /// </remarks>
  /// </summary>
    public partial class AzureBlogProvider : BlogProvider
  {
        string errMessage;
        PagesMethods PagesMethods = new PagesMethods();

    /// <summary>
    /// Retrieves a Page from the data store.
    /// </summary>
    public override Page SelectPage(Guid id)
    {     

      return (Page)PagesMethods.CreateObject(PagesMethods.GetEntity(id.ToString(), out errMessage)); 
    }

    /// <summary>
    /// Inserts a new Page to the data store.
    /// </summary>
    public override void InsertPage(Page page)
    {
        PagesMethods.Insert(page,out  errMessage);
    }

    /// <summary>
    /// Updates a Page.
    /// </summary>
    public override void UpdatePage(Page page)
    {
        PagesMethods.Update (page, out  errMessage);
    }

    /// <summary>
    /// Deletes a page from the data store.
    /// </summary>
    public override void DeletePage(Page page)
    {
        PagesMethods.Delete(page.Id.ToString());

      if (Page.Pages.Contains(page))
        Page.Pages.Remove(page);
    }

    /// <summary>
    /// Retrieves all pages from the data store
    /// </summary>
    /// <returns>List of Pages</returns>
    public override List<Page> FillPages()
    {     
        List<Page> pages =PagesMethods.GetPages(null,out errMessage).ToList();
        foreach (Page o in pages)
        {
            o.MarkOld();
        }
        return pages;
    }


  }
}
